﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Globalization;
using Huayou.Utils;

namespace HySoft.Cash
{
    public static class AppSettings
    {
        /// <summary>
        /// 劲量使用CurrentCulture属性
        /// </summary>
        public static string DateFormatAU
        {
            get
            {
                string dateFormatAU = ConfigurationManager.AppSettings["DateFormatAU"];
                if (string.IsNullOrEmpty(dateFormatAU))
                {
                    dateFormatAU = "dd/MM/yyyy";
                }

                return dateFormatAU;
            }
        }

        public static CultureInfo CurrentCulture
        {
            get
            {
                return SystemCulture;
            }
        }

        public static CultureInfo SystemCulture
        {
            get
            {
                string cultureName = ConfigurationManager.AppSettings["cultureNameSystem"];
                if (string.IsNullOrEmpty(cultureName))
                {
                    cultureName = "en-AU";
                }

                CultureInfo culture = new CultureInfo(cultureName);
                return culture;
            }
        }

        public static CultureInfo DataBaseCulture
        {
            get
            {
                string cultureName = ConfigurationManager.AppSettings["cultureNameDataBase"];
                if (string.IsNullOrEmpty(cultureName))
                {
                    cultureName = "en-US";
                }

                CultureInfo culture = new CultureInfo(cultureName);
                return culture;
            }
        }

        /// <summary>
        /// 数据库在美国，其日期格式
        /// </summary>
        public static string DateFormatUS
        {
            get
            {
                string dateFormatUS = Config.GetSetting("DateFormatUS");
                if (string.IsNullOrEmpty(dateFormatUS))
                {
                    dateFormatUS = "MM/dd/yyyy";
                }

                return dateFormatUS;
            }
        }

        public static bool SmtpEnableSsl
        {
            get
            {
                string smtpEnableSslValue = ConfigurationManager.AppSettings["SmtpEnableSsl"];
                if (string.IsNullOrEmpty(smtpEnableSslValue))
                {
                    smtpEnableSslValue = "false";
                }

                bool smtpEnableSsl = false;
                bool.TryParse(smtpEnableSslValue, out smtpEnableSsl);

                return smtpEnableSsl;
            }
        }

        /// <summary>
        /// 系统的链接字符串信息
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                string connectString = ConfigurationManager.AppSettings["SQLConnString"];
                return connectString;
            }
        }


        private static int zoneDiff = 25;
        /// <summary>
        /// 本地时间跟服务器的时差
        /// </summary>
        public static int ZoneDiff
        {
            get
            {
                if (zoneDiff == 25)
                {
                    string temp = System.Configuration.ConfigurationSettings.AppSettings["ZoneDiff"];

                    if (temp != null && temp != string.Empty)
                    {
                        zoneDiff = Convert.ToInt32(temp);
                    }
                    else
                    {
                        zoneDiff = 0;
                    }
                }

                return zoneDiff;
            }
        }

        private static int invoiceSentDays = -999;
        public static int InvoiceSentDays
        {
            get
            {
                if (invoiceSentDays == -999)
                {
                    string temp = System.Configuration.ConfigurationSettings.AppSettings["InvoiceSentDays"];

                    if (temp != null && temp != string.Empty)
                    {
                        invoiceSentDays = Convert.ToInt32(temp);
                    }
                }
                else
                {
                    invoiceSentDays = 49;
                }

                return invoiceSentDays;
            }
        }


        private static int invoiceOverDueDays = -999;
        public static int InvoiceOverDueDays
        {
            get
            {
                if (invoiceOverDueDays == -999)
                {
                    string temp = ConfigurationManager.AppSettings["invoiceOverDueDays"];

                    if (temp != null && temp != string.Empty)
                    {
                        invoiceOverDueDays = Convert.ToInt32(temp);
                    }
                }
                else
                {
                    invoiceOverDueDays = 56;
                }

                return invoiceOverDueDays;
            }
        }

        private static int genericStatementDay = 32;
        /// <summary>
        /// 每月生成Statement的日数
        /// </summary>
        public static int GenericStatementDay
        {
            get
            {
                if (genericStatementDay == 32)
                {
                    string temp = System.Configuration.ConfigurationSettings.AppSettings["GenericStatementDay"];

                    if (temp != null && temp != string.Empty)
                    {
                        genericStatementDay = Convert.ToInt32(temp);
                    }
                }
                else
                {
                    genericStatementDay = 1;
                }

                return genericStatementDay;
            }
        }

        private static string sentMailAccount = string.Empty;
        public static string SentMailAccount
        {
            get 
            {
                if (sentMailAccount == string.Empty)
                {
                    string temp = ConfigurationManager.AppSettings["SentMailAccount"];
                    if (string.IsNullOrEmpty(temp) == false)
                    {
                        sentMailAccount = temp;
                    }
                }

                return sentMailAccount;
            }
        }
    }
}
